#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
<<<<<<< HEAD
@File Name  : 3_依赖倒置原则.py
@Author     : LeeCQ
@Date-Time  : 2019/12/4 15:56

*原则解释：*

    1 高层级的模块不应该依赖于低层次的模块，它应该依赖于低层次模块的抽象
    2 抽象不应该依赖于具体，具体应该依赖于抽象
    3 高层次的模块不应该依赖于低层次的模型，它应该依赖于低层次模块的抽象

** 2019.12.4 **
    经测试，不依赖与抽象依旧可以执行， 意义何在？
"""

import abc


class Car(object):
    __metaclass__ = abc.ABCMeta

    @abc.abstractmethod
    def car_run(self, *args, **kwargs):
        pass

    @abc.abstractmethod
    def car_turn(self, *args, **kwargs):
        pass

    @abc.abstractmethod
    def car_stop(self, *args, **kwargs):
        pass


class Ford(Car):
    def __init__(self):
        self.type = 'ford'

    def car_run(self):
        print('%s is running' % self.type)

    def car_turn(self):
        print('%s is turning' % self.type)

    def car_stop(self):
        print('%s is stopping' % self.type)


class Buick(Car):
    def __init__(self):
        self.type = 'buick'

    def car_run(self):
        print('%s is running' % self.type)

    def car_turn(self):
        print('%s is turning' % self.type)

    def car_stop(self):
        print('%s is stopping' % self.type)


class Cadillac(Car):
    def __init__(self):
        self.type = 'cadillac'

    def car_run(self):
        print('%s is running' % self.type)

    def car_turn(self):
        print('%s is turning' % self.type)

    def car_stop(self):
        print('%s is stopping' % self.type)


class AutoSystem(object):

    def __init__(self, car):
        self.car = car

    def car_run(self):
        self.car.car_run()

    def car_turn(self):
        self.car.car_turn()

    def car_stop(self):
        self.car.car_stop()


if __name__ == '__main__':
    ford = Ford()
    buick = Buick()
    cadillac = Cadillac()
    autosystem = AutoSystem(ford)
    autosystem.car_run()
    autosystem.car_turn()
    autosystem.car_stop()
    autosystem.car = buick
    print('*' * 100)
    autosystem.car_run()
    autosystem.car_turn()
    autosystem.car_stop()
    print("*" * 100)
    autosystem.car = cadillac
    autosystem.car_run()
    autosystem.car_turn()
    autosystem.car_stop()
=======
@File Name  : 1_依赖倒置原则.py
@Author     : LeeCQ
@Date-Time  : 2019/12/4 15:56

"""
>>>>>>> 0f663d9cdbaca672411c54e3f484639a12f0b328
